package cn.com.captureNetPacket.util;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class Log2File {
	static File directory = new File("");//设定为当前文件夹
	static String logDirectory=null;
	
	public static void writeFile(String fileName,String message){
		
	    try {
			if(logDirectory==null)logDirectory=directory.getAbsolutePath()+"\\logs\\";
			fileName=fileName.replaceAll("->", "to");
			 fileName=fileName.replaceAll(":", "port");
		//	System.out.println("-------->"+fileName);
			//如果文件存在，则追加内容；如果文件不存在，则创建文件
			File f=new File(logDirectory+fileName+".txt");
			FileWriter fw = null;
			fw = new FileWriter(f, true);
			PrintWriter pw = new PrintWriter(fw);
			pw.println(message+"\r\n");
			fw.flush();
			pw.close();
			fw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}//获取标准的路径 
	}
}
